import React, {Component} from 'react';
import Markdown from 'react-markdown';
import {Anchor, Row, Col} from 'antd';

const {Link} = Anchor;


class JsPage extends Component {
    constructor(props) {
        super(props);
    }




    render() {

        return (
            <div style={{background: "#c0d2bc"}}>
                <Row>
                    <Col span={19}>
                        <h2 id="stream">stream通用语法</h2>
                        <Markdown source={"创建stream -> 转换stream ->聚合stream\n" +
                        "\n" +
                        "Stream的定义：\n" +
                        "Stream是元素的集合，这点让Stream看起来用些类似Iterator；\n" +
                        "可以支持顺序和并行的对原Stream进行汇聚的操作；"}/>

                        <h3 id="create_stream"> 创建stream</h3>
                        <Markdown source={"1、Stream.of(1,2,3);\n\n" +
                        "2、list.stream();"}/>

                        <h3 id="转换stream"> 转换stream </h3>
                        <Markdown source={
                        " distinct\n" +
                        "    \n" +
                        "    Stream.of(1,2,3,4,1,2,3).distinct().forEach(c -> System.out.println(c));\n" +
                        "filter\n" +
                        "\n" +
                        "    Stream.of(1,2,3,4,1,2,3).filter(x ->(x>3)).forEach(c -> System.out.println(c));\n" +
                        "map\n" +
                        "\n" +
                        "    Stream.of(1,2,3,4).map(x ->(x+2)).forEach(c -> System.out.println(c));\n" +
                        "flatMap\n" +
                        "    \n" +
                        "    .\n" +
                        "limit  获取其前N个元素\n" +
                        "    \n" +
                        "    Stream.of(1,2,3,4).limit(2).forEach(c -> System.out.println(c)); \n" +
                        "skip  丢弃前N个元素\n" +
                        "\n" +
                        "    Stream.of(1,2,3,4).skip(2).forEach(c -> System.out.println(c));\n"}/>
                        <h3 id="聚合stream"> 聚合stream </h3>
                        <Markdown source={
                        "  collect\n" +
                        "    \n" +
                        "     List<Integer> ints = Stream.of(1,2,3,4,5,6,7).skip(2).collect(Collectors.toList());\n" +
                        "     ints.forEach(c -> System.out.println(c));   \n" +
                        "count\n" +
                        "    \n" +
                        "    long size = Stream.of(1,2,3,4,5,6,7).skip(2).count() ;\n" +
                        "reduce\n" +
                        "\n" +
                        "    Optional<Integer> s = Stream.of(1,2,3,4,5,6,7,8,9,10).reduce((a, b) -> (a + b)) ;\n" +
                        "    System.out.println(s.get()); \n" +
                        "    \n" +
                        "    Integer s = Stream.of(1,2,3,4,5,6,7,8,9,10).reduce(0,(a, b) -> (a + b)) ;\n"}/>

                        <h2 id="define_lambda"> 定义lambda表达式 </h2>
                        <Markdown source={"抽象一下lambda表达式的一般语法 : () ->{return something;}\n" +
                        "\n" +
                        "    Stream.of(1,2,3,4,1,2,3).distinct().map(x -> {return  x+21 ;}).forEach(e -> System.out.println(e));\n"}/>

                        <h3 id="ref"> 参考 </h3>
                        <Markdown source={"https://www.ibm.com/developerworks/cn/java/j-lo-java8streamapi/"}/>

                    </Col>
                    <Col span={5}>
                        <Anchor showInkInFixed="true" style={{background: "#ebefe0"}}>
                            <Link href="#stream" title="stream通用语法">
                                <Link href="#create_stream" title="创建stream"/>
                                <Link href="#转换stream" title="转换stream"/>
                                <Link href="#聚合stream" title="聚合stream"/>
                            </Link>
                            <Link href="#define_lambda" title="定义lambda表达式"/>
                            <Link href="#ref" title="参考"/>
                        </Anchor>
                    </Col>
                </Row>
            </div>
        );
    }
}

export default JsPage;